export function useDicts() {
    // e签宝认证授权状态
    const EAuthStatus = [
        {
            label: '未认证',
            value: '1',
        },
        {
            label: '已认证',
            value: '2',
        },
        {
            label: '已授权',
            value: '3',
        },
        {
            label: '重新认证',
            value: '4',
        },
    ]

    const dicts = {
        EAuthStatus,
    }

    const useDict = (key: string, value: any, getLabel = true, source?: any) => {
        const data = source || dicts
        if (Array.isArray(value)) {
            const labels: any = []
            value.forEach((val: any) => {
                let tgt = data[key].find((v: any) => v.value === `${val}`)?.label || val
                if (!getLabel)
                    tgt = data[key].find((v: any) => v.label === `${val}`)?.value || val

                labels.push(tgt)
            })
            return labels.join(',')
        }
        let target = data[key].find((v: any) => v.value === `${value}`)?.label || value
        if (!getLabel)
            target = data[key].find((v: any) => v.label === `${value}`)?.value || value

        return target
    }

    return { dicts, useDict }
}
